package com.ruoyi.project.fire.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.project.fire.domain.FireRiskPoint;
import com.ruoyi.project.fire.mapper.FireInspectionProjectMapper;
import com.ruoyi.project.fire.domain.FireInspectionProject;
import com.ruoyi.project.fire.service.IFireInspectionProjectService;

/**
 * 存储排查项目名称Service业务层处理
 * 
 * @author 布衣
 * @date 2025-05-13
 */
@Service
public class FireInspectionProjectServiceImpl implements IFireInspectionProjectService 
{
    @Autowired
    private FireInspectionProjectMapper fireInspectionProjectMapper;

    /**
     * 查询存储排查项目名称
     * 
     * @param projectId 存储排查项目名称主键
     * @return 存储排查项目名称
     */
    @Override
    public FireInspectionProject selectFireInspectionProjectByProjectId(Long projectId)
    {
        return fireInspectionProjectMapper.selectFireInspectionProjectByProjectId(projectId);
    }

    /**
     * 查询存储排查项目名称列表
     * 
     * @param fireInspectionProject 存储排查项目名称
     * @return 存储排查项目名称
     */
    @Override
    public List<FireInspectionProject> selectFireInspectionProjectList(FireInspectionProject fireInspectionProject)
    {
        return fireInspectionProjectMapper.selectFireInspectionProjectList(fireInspectionProject);
    }

    /**
     * 新增存储排查项目名称
     * 
     * @param fireInspectionProject 存储排查项目名称
     * @return 结果
     */
    @Transactional
    @Override
    public int insertFireInspectionProject(FireInspectionProject fireInspectionProject)
    {
        int rows = fireInspectionProjectMapper.insertFireInspectionProject(fireInspectionProject);
        insertFireRiskPoint(fireInspectionProject);
        return rows;
    }

    /**
     * 修改存储排查项目名称
     * 
     * @param fireInspectionProject 存储排查项目名称
     * @return 结果
     */
    @Transactional
    @Override
    public int updateFireInspectionProject(FireInspectionProject fireInspectionProject)
    {
        fireInspectionProjectMapper.deleteFireRiskPointByProjectId(fireInspectionProject.getProjectId());
        insertFireRiskPoint(fireInspectionProject);
        return fireInspectionProjectMapper.updateFireInspectionProject(fireInspectionProject);
    }

    /**
     * 批量删除存储排查项目名称
     * 
     * @param projectIds 需要删除的存储排查项目名称主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFireInspectionProjectByProjectIds(Long[] projectIds)
    {
        fireInspectionProjectMapper.deleteFireRiskPointByProjectIds(projectIds);
        return fireInspectionProjectMapper.deleteFireInspectionProjectByProjectIds(projectIds);
    }

    /**
     * 删除存储排查项目名称信息
     * 
     * @param projectId 存储排查项目名称主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFireInspectionProjectByProjectId(Long projectId)
    {
        fireInspectionProjectMapper.deleteFireRiskPointByProjectId(projectId);
        return fireInspectionProjectMapper.deleteFireInspectionProjectByProjectId(projectId);
    }

    /**
     * 新增排查项目信息
     * 
     * @param fireInspectionProject 存储排查项目名称对象
     */
    public void insertFireRiskPoint(FireInspectionProject fireInspectionProject)
    {
        List<FireRiskPoint> fireRiskPointList = fireInspectionProject.getFireRiskPointList();
        Long projectId = fireInspectionProject.getProjectId();
        if (StringUtils.isNotNull(fireRiskPointList))
        {
            List<FireRiskPoint> list = new ArrayList<FireRiskPoint>();
            for (FireRiskPoint fireRiskPoint : fireRiskPointList)
            {
                fireRiskPoint.setProjectId(projectId);
                list.add(fireRiskPoint);
            }
            if (list.size() > 0)
            {
                fireInspectionProjectMapper.batchFireRiskPoint(list);
            }
        }
    }
}
